package com.learning.jquizenglish.screen.home;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.learning.jquizenglish.R;
import com.learning.jquizenglish.activity.DoQuizActivity;
import com.learning.jquizenglish.activity.FlashCardActivity;
import com.learning.jquizenglish.activity.MainActivity;
import com.learning.jquizenglish.common.fragment.JQuizEnglishFragment;
import com.learning.jquizenglish.network.JQuizEnglishApi.Level;
import com.learning.jquizenglish.network.JQuizEnglishApi.QuestionType;
import com.learning.jquizenglish.screen.doquiz.DoQuizScreen;
import com.learning.jquizenglish.screen.doquiz.DoQuizSession;
import com.learning.jquizenglish.screen.flashcard.FlashCardCategoryScreen;
import com.learning.jquizenglish.screen.more.HelpScreen;
import com.learning.jquizenglish.screen.more.HighScoreScreen;
import com.learning.jquizenglish.screen.more.StatisticScreen;
import com.learning.jquizenglish.screen.settings.SettingScreen;
import com.learning.jquizenglish.widget.SquareImageView;

public class HomeScreen extends JQuizEnglishFragment implements OnClickListener{

	private SquareImageView imgSettings;
	private SquareImageView imgHelp;
	private SquareImageView imgElementary;
	private SquareImageView imgIntermediate;
	private SquareImageView imgAdvanced;
	private SquareImageView imgProfile;
	private SquareImageView imgLearningFeed;
	private SquareImageView imgFlashCard;
	private SquareImageView imgHighScore;
	private SquareImageView imgStatistic;
	private SquareImageView imgBottom;
	
	@Override
	protected View onCreateContentView(LayoutInflater inflater,
			ViewGroup container) {
		View v = inflater.inflate(R.layout.screen_home, container, false);
		imgSettings 	= (SquareImageView) v.findViewById(R.id.imgSetting);
		imgHelp			= (SquareImageView) v.findViewById(R.id.imgHelp);
		imgElementary	= (SquareImageView) v.findViewById(R.id.imgElementary);
		imgIntermediate = (SquareImageView) v.findViewById(R.id.imgIntermediate);
		imgAdvanced		= (SquareImageView) v.findViewById(R.id.imgAdvanced);
		imgProfile		= (SquareImageView) v.findViewById(R.id.imgProfile);
		imgLearningFeed = (SquareImageView) v.findViewById(R.id.imgLearningFeed);
		imgFlashCard	= (SquareImageView) v.findViewById(R.id.imgFlashCard);
		imgHighScore	= (SquareImageView) v.findViewById(R.id.imgHighScore);
		imgStatistic	= (SquareImageView) v.findViewById(R.id.imgStatistics);
		imgBottom		= (SquareImageView) v.findViewById(R.id.imgBottom);
		imgSettings.setOnClickListener(this);
		imgHelp.setOnClickListener(this);
		imgElementary.setOnClickListener(this);
		imgIntermediate.setOnClickListener(this);
		imgAdvanced.setOnClickListener(this);
		imgProfile.setOnClickListener(this);
		imgLearningFeed.setOnClickListener(this);
		imgFlashCard.setOnClickListener(this);
		imgHighScore.setOnClickListener(this);
		imgStatistic.setOnClickListener(this);
		imgBottom.setOnClickListener(this);
		return v;
	}

	private void showSettingScreen(){
		((MainActivity)getActivity()).switchContent(new SettingScreen(), true);
	}
	
	private void showHelpScreen(){
		((MainActivity)getActivity()).switchContent(new HelpScreen(), true);
	}
	
	private void showDoQuizScreen(){
//		((MainActivity)getActivity()).switchContent(new DoQuizScreen(), true);
		((MainActivity)getActivity()).startDoQuizActivityForResult(new Intent(getActivity(), DoQuizActivity.class));
	}
	
	private void showHighScore(){
		((MainActivity)getActivity()).switchContent(new HighScoreScreen(), true);
	}
	
	private void showStatistic(){
		((MainActivity)getActivity()).switchContent(new StatisticScreen(), true);
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.imgSetting:
			showSettingScreen();
			break;
		case R.id.imgHelp:
			showHelpScreen();
			break;
		case R.id.imgElementary:
			DoQuizSession.getInstance().setQuestionType(QuestionType.QUESTION);
			DoQuizSession.getInstance().setQuestionLevel(Level.ELEMENTARY);
			showDoQuizScreen();
			break;
		case R.id.imgIntermediate:
			DoQuizSession.getInstance().setQuestionType(QuestionType.QUESTION);
			DoQuizSession.getInstance().setQuestionLevel(Level.INTERMEDIATE);
			showDoQuizScreen();
			break;
		case R.id.imgAdvanced:
			DoQuizSession.getInstance().setQuestionType(QuestionType.QUESTION);
			DoQuizSession.getInstance().setQuestionLevel(Level.ADVANCED);
			showDoQuizScreen();
			break;
		case R.id.imgProfile:
			((MainActivity)getActivity()).getMainScreen().setCurrentPage(0);
			break;
		case R.id.imgLearningFeed:
			((MainActivity)getActivity()).getMainScreen().setCurrentPage(2);
			break;
		case R.id.imgFlashCard:
			getActivity().startActivity(new Intent(getActivity(), FlashCardActivity.class));
			break;
		case R.id.imgHighScore:
			showHighScore();
			break;
		case R.id.imgStatistics:
			showStatistic();
			break;
		case R.id.imgBottom:
			showHelpScreen();
			break;
		default:
			break;
		}
	}

}

